﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Namespace Arwani
    Partial Class _Default1
        Inherits System.Web.UI.Page
        '<%# DataBinder.Eval(Container.DataItem, "ViewCount") %>
        Protected strBrands As String = ""
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If IsPostBack Then Exit Sub
            Call getDivisionLeft()
            Call getDivisionRight()
            Call loadFeaturedProject()
            Call loadBrandImages()
        End Sub

        Public Sub loadFeaturedProject()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from product where isfeatured=1 ORDER BY rand() limit 0,4"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Me.dtFeaturedProduct.DataSource = dtTable
            Me.dtFeaturedProduct.DataBind()
        End Sub

        Public Function getProductImage(ByVal pid As Integer) As String
            Dim arwCon As New ArwaniController
            Dim strReturn As String = ""
            Dim strQ As String = "select * from product_images where productid=" & pid
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("productimage")) Then strReturn = getImage("Products", "Thumb_Four_", dtTable.Rows(0)("productimage"))
            Else
                strReturn = "images/main_banner.png"
            End If
            Return strReturn
        End Function

        Public Sub loadBrandImages()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from brand"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)

            Dim iCount As Integer = 0
            For iCount = 0 To dtTable.Rows.Count - 1
                If Not IsDBNull(dtTable.Rows(iCount)("brandpic")) Then strBrands &= "<img src='" & getImage("Brands", "Thumb_small_", dtTable.Rows(iCount)("brandpic")) & "' alt='pic' />"
            Next
        End Sub


        Public Sub getDivisionLeft()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from division limit 0,3"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Me.dtDivisionLeft.DataSource = dtTable
            Me.dtDivisionLeft.DataBind()
        End Sub

        Public Sub getDivisionRight()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from division limit 3,6"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Me.dtDivisionRight.DataSource = dtTable
            Me.dtDivisionRight.DataBind()
        End Sub

        Public Function getImage(ByVal _Folder As String, ByVal Prefix As String, ByVal imgSrc As String) As String
            Dim strReturn As String = "images/main_banner.png"
            If File.Exists(Server.MapPath(_Folder & "/" & Prefix & imgSrc)) Then
                strReturn = _Folder & "/" & Prefix & imgSrc
            End If
            Return strReturn
        End Function

        Protected Sub dtDivisionLeft_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtDivisionLeft.ItemCommand
            If e.CommandName = "View" Then
                Response.Redirect("Brands.aspx?divid=" & CInt(e.CommandArgument))
            End If
        End Sub

        Protected Sub dtDivisionRight_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtDivisionRight.ItemCommand
            If e.CommandName = "View" Then
                Response.Redirect("Brands.aspx?divid=" & CInt(e.CommandArgument))
            End If
        End Sub


        Protected Sub lnkSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSend.Click
            Dim strMessage As String = ""
            strMessage = "Following information has been sent in the contact form<br>"
            strMessage &= "Name : " & Me.txtName.Text & "<Br>"
            strMessage &= "Phone : " & Me.txtPhone.Text & "<Br>"
            strMessage &= "Email : " & Me.txtEmail.Text & "<Br>"
            strMessage &= "Message : " & Me.txtMessage.Text & "<Br>"

            MailHelper.SendMailMessage(Me.txtEmail.Text, "info@arwani.ae", "", "", "Contact From - Arwani Trading Website", strMessage)
            Me.lblErrorMessage.Visible = True
            Me.lblErrorMessage.InnerText = "Message Sent"
        End Sub
    End Class
End Namespace
